package com.bwie.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.bwie.pojo.Result;
import com.bwie.pojo.dto.RechargeDto;
import com.bwie.pojo.po.Recharge;
import com.bwie.pojo.vo.RechargeVo;
import com.bwie.service.RechargeService;
import com.bwie.utils.poi.EasyPoiUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/recharge")
public class RechargeController {
    @Autowired
    private RechargeService rechargeService;
    @ResponseBody
    @GetMapping("getRechargeList")
    public PageInfo<Recharge> getRechargeList(RechargeDto rechargeDto){
        return rechargeService.getRechargeList(rechargeDto);
    }

    @ResponseBody
    @PostMapping("addRecharge")
    public Result addRecharge(@RequestBody Recharge recharge) throws Exception {
        return rechargeService.addRechsrge(recharge);
    }






    @ResponseBody
    @GetMapping("getRecharge")
    public PageInfo<RechargeVo> getRecharge(RechargeDto rechargeDto){
       return rechargeService.getRecharge(rechargeDto);
    }







    @ResponseBody
    @PostMapping("addMoney")
    public Result addMoney(@RequestBody RechargeVo rechargeVo){
        rechargeService.addMoney(rechargeVo);
        return Result.success();
    }


    /**
     * 导入
     * @param file
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("daoru")
    public Result daoru(@RequestParam("file") MultipartFile file) throws Exception {
        ImportParams importParams = new ImportParams();
        importParams.setHeadRows(1);
        List<Recharge> list = ExcelImportUtil.importExcel(file.getInputStream(), Recharge.class, importParams);

        //批量添加
        rechargeService.addRechsrgeList(list);
        return Result.success();
    }
}
